package com.ycg.blog.controller;

import com.ycg.blog.common.R;
import com.ycg.blog.pojo.Category;
import com.ycg.blog.pojo.vo.CategoryVo;
import com.ycg.blog.pojo.vo.SimpleArticleVo;
import com.ycg.blog.service.CategoryService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author YCG
 * @date 2024-02-28 11:25R
 * @description 针对分类项目的增删除
 */
@RestController
@RequestMapping("/categories")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @GetMapping("/get")
    public R<List<CategoryVo>> getCategories() {
        return categoryService.getCategoryList();
    }

    @PostMapping("add")
    public R<String> addCategories(String name,Integer parentId) {
        return categoryService.addCategories(name, parentId);
    }

    @GetMapping("/getArticles")
    public R<List<SimpleArticleVo>> getSimpleArticles(Integer categoryId) {
        return categoryService.getSimpleArticlesByCategoryId(categoryId);
    }

    @PutMapping("/put")
    public R<String> updateCategoryName(Integer categoryId, String newName) {
        return categoryService.updateCategoryName(categoryId,newName);
    }

}
